package com.xyd.Servlet;

import com.xyd.Biz.CommodityBiz;
import com.xyd.Biz.Impl.CommodityBizImpl;
import com.xyd.Biz.Impl.ProductCarBizImpl;
import com.xyd.Biz.ProductCarBiz;
import com.xyd.Entity.Commodity;
import com.xyd.Entity.ProductCar;
import com.xyd.Entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @ClassName: ShowProductInCarServlet
 * @Description:
 * @Author 余全盛
 * @Date: 2021/10/15 20:22
 */
@WebServlet("/html/ShowProductInCarServlet")
public class ShowProductInCarServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        ProductCarBiz productCarBiz = new ProductCarBizImpl();
        CommodityBiz commodityBiz = new CommodityBizImpl();
        User user = (User) session.getAttribute("user");
        List<ProductCar> productCarList = productCarBiz.selectAllProductCarByID(user.getUserid());
        List<Commodity> commodityList = commodityBiz.getAllCommodity();
        session.setAttribute("productCarList", productCarList);
        session.setAttribute("commodityList", commodityList);
        resp.setContentType("text/html;charset=UTF-8");
        resp.sendRedirect("/shopping/html/shopping.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
